import React from "react";
import { Link, Routes, Route, useParams } from "react-router-dom";

const Home = () => {
  return <div>这是首页页面</div>;
};

const About = () => {
  return <div>这是关于页面</div>;
};

const Detail = () => {
  // 6版本的路由的props里面就没有路由信息
  // 但是我们可以直接使用hooks
  // console.log(props);

  const params = useParams();

  return <div>这是详情页页面 - {params.id}</div>;
};

const App = () => {
  return (
    <>
      <h2>react-router-v6-动态路由</h2>
      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
        <li>
          <Link to="/detail/234">详情页</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/home" element={<Home></Home>}></Route>
        <Route path="/about" element={<About />}></Route>
        {/* <Route path="/detail/:id" element={<Detail />}></Route> */}

        {/* 现在又增加了一个功能，叫动态可选参数 */}
        <Route path="/detail" element={<Detail />}>
          <Route path=":id" element={<Detail />}></Route>
        </Route>
      </Routes>
    </>
  );
};

export default App;
